#include<bits/stdc++.h>
using namespace std;
#define int long long
#define _i __int128
int n, c;
int b[1000005];
vector<int>a[1000005];
vector<pair<int, int> > d[1000005];
map<int, int> mp;
vector<pair<int, int> > vec;
vector<pair<int, int> > merge(vector<pair<int, int> > x, vector<pair<int, int> > y, int xs1, int xs2){
    vector<pair<int, int> > ans;
    int z1 = 1, z2 = 1;
    ans.emplace_back(1, x[0].second + y[0].second);
    while(z1 < x.size() && z2 < y.size()){
        if(x[z1].first == y[z2].first){
            ans.emplace_back(x[z1].first, x[z1].second + y[z2].second);
            z1++, z2++;
        }else if(x[z1].first < y[z2].first){
            ans.emplace_back(x[z1].first, x[z1].second + y[z2 - 1].second + (y[z2].second - y[z2 - 1].second) / (y[z2].first - y[z2 - 1].first) * (x[z1].first - y[z2 - 1].first));
            z1++;
        }else{
            ans.emplace_back(y[z2].first, y[z2].second + x[z1 - 1].second + (x[z1].second - x[z1 - 1].second) / (x[z1].first - x[z1 - 1].first) * (y[z2].first - x[z1 - 1].first));
            z2++;
        }
    }
    while(z1 < x.size()){
        ans.emplace_back(x[z1].first, x[z1].second + y.back().second + (x[z1].first - y.back().first) * xs2);
        z1++;
    }
    while(z2 < y.size()){
        ans.emplace_back(y[z2].first, y[z2].second + x.back().second + (y[z2].first - x.back().first) * xs1);
        z2++;
    }
    return ans;
}
void solve(int l, int r){
    if(l == r){
        return;
    }
    int mid = l+r>>1;
    solve(l, mid);
    solve(mid + 1, r);
    d[l] = merge(d[l], d[mid + 1], mid - l + 1, r - mid);
    vector<pair<int, int> > kong;
    swap(kong, d[mid + 1]);
}
int read(){
    char ch = getchar();
    int s = 0;
    while(ch < '0' || ch > '9')ch = getchar();
    while('0' <= ch && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s;
}
void write(_i x){
    if(x > 9)write(x / 10);
    putchar(x % 10 + '0');
}
signed main(){
    freopen("list.in", "r", stdin);
    freopen("list.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        int len;
        cin >> len;
        while(len--){
            int x;
            cin >> x;
            a[i].emplace_back(x);
        }
        sort(a[i].begin(), a[i].end());
        a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());
        for(auto j : a[i])mp[j]++;
    }
    cin >> c;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++){
        vector<int> del;
        for(int j = 1; j < a[i].size(); j++){
            del.emplace_back(a[i][j] - a[i][j - 1]);
            vec.emplace_back(a[i][j] - a[i][j - 1] + 1, a[i][j]);
        }
        sort(del.begin(), del.end());
        int nw = a[i].size();
        int ans = nw;
        int pre = 1;
        if(!del.size() || del[0] > 1)d[i].emplace_back(1, ans);
        for(int j = 0; j < del.size(); j++){
            int en = j;
            while(en + 1 < del.size() && del[en] == del[en + 1])en++;
            ans += (del[j] - pre) * nw;
            nw -= en - j + 1;
            d[i].emplace_back(del[j], ans);
            pre = del[j];
            j = en;
        }
    }
    solve(1, n);
    _i ans = 0;
    for(auto [i, x] : mp)ans += b[x] * x;
    sort(vec.begin(), vec.end());
    int z = 0;
    int z_ = 0;
    _i mn = 1e30;
    vector<int>qwq;
    vector<int>sp;
    for(auto [i, val] : d[1])sp.emplace_back(i);
    for(auto [i, _] : vec){
        sp.emplace_back(i);
    }
    sort(sp.begin(), sp.end());
    sp.erase(unique(sp.begin(), sp.end()), sp.end());
    for(auto i : sp){
        while(z < vec.size() && vec[z].first == i){
            int p = mp[vec[z].second];
            ans -= b[p] * p;
            mp[vec[z].second]--;
            p = mp[vec[z].second];
            ans += b[p] * p;
            z++;
        }
        while(z_ + 1 < d[1].size() && d[1][z_ + 1].first <= i)z_++;
        _i val = d[1][z_].second + (z_ + 1 == d[1].size() ? (i - d[1][z_].first) * n : (i - d[1][z_].first) * ((d[1][z_ + 1].second - d[1][z_].second) / (d[1][z_ + 1].first - d[1][z_].first)));
        val *= c;
        if(ans + val < mn){
            mn = ans + val;
            qwq.clear();
            qwq.emplace_back(i);
        }else if(ans + val == mn){
            qwq.emplace_back(i);
        }
    }
    write(mn);
    printf(" ");
    write(qwq.size());
    puts("");
    for(auto i : qwq){
        write(i);
        printf(" ");
    }
    puts("");
    return 0;
}